package scripts;
import javax.swing.JOptionPane;
import bot.ScriptMethods;

public class Superheat extends ScriptMethods implements Runnable {

	private int ore;
	private int Nore;
	private int coal;
	private int Ncoal;
	private int bar;

	public void start() {
		getAccountSettings();
		System.gc();

		Object[] options = {"Bronze", "Iron", "Steel", "Mithril", "Adamantite", "Runite", "Silver", "Gold"};
		String res1 = (String)JOptionPane.showInputDialog(null, "", "Superheater", JOptionPane.PLAIN_MESSAGE, null, options, options[0]);

		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
		
		if (res1.equals("Bronze")) {
			ore = 150;
			Nore = 14;
			coal = 202;
			Ncoal = 14;
			bar = 169;
		}
		if (res1.equals("Iron")) {
			ore = 151;
			Nore = 29;
			bar = 170;
		}
		if (res1.equals("Steel")) {
			ore = 151;
			Nore = 9;
			coal = 155;
			Ncoal = 18;
			bar = 171;
		}
		if (res1.equals("Mithril")) {
			ore = 153;
			Nore = 5;
			coal = 155;
			Ncoal = 20;
			bar = 173;
		}
		if (res1.equals("Adamantite")) {
			ore = 154;
			Nore = 4;
			coal = 155;
			Ncoal = 24;
			bar = 174;
		}
		if (res1.equals("Runite")) {
			ore = 409;
			Nore = 3;
			coal = 155;
			Ncoal = 24;
			bar = 408;
		}
		if (res1.equals("Silver")) {
			ore = 383;
			Nore = 29;
			bar = 384;
		}
		if (res1.equals("Gold")) {
			ore = 152;
			Nore = 29;
			bar = 172;
		}
	}

	public void stop() {
		System.gc();
		scriptThread = null;
		scriptRunning = false;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();

				if (!invContains(ore) && !bankOpen()) {
					openBank();
					wait(2000);
				}

				if (bankOpen()) {
					if (invContains(ore)) {
						depositAll(ore);
						wait(random(610, 750));
					}
					if (invContains(170)) {
						depositAll(170);
						wait(random(610, 750));
					}
					if (invContains(coal)) {
						depositAll(coal);
						wait(random(610, 750));
					}
					depositAll(bar);
					wait(random(610, 750));
					withdraw(coal, Ncoal);
					wait(random(610, 750));
					withdraw(ore, Nore);
					wait(random(610, 750));
					closeBank();
					wait(random(610, 750));
				}

				if (invContains(ore) && !isSleeping() && !bankOpen()) {
					superHeatItem(ore);
					wait(random(1500, 2000));
				}
				wait(150);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (!isLoggedIn())
			doLogin();
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
	}
}